package com.practice.bootdemo.service.impl;

import com.practice.bootdemo.service.AsyncService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author :Administrator
 * @description: TODO edit class Description
 * @create date: 2022/12/5 21:48
 */
@Service
public class AsyncServiceImpl implements AsyncService {

    @Async
    @Override
    public void async1() {
        try {
            for (int i = 0; i < 10; i++) {
                String threadName =Thread.currentThread().getName();
                System.out.println(threadName+" async1 :"+i);
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            System.out.println("异常1....");
        }
    }

    @Async
    @Override
    public void async2() {
        try {
            for (int i = 0; i < 10; i++) {
                String threadName =Thread.currentThread().getName();
                System.out.println(threadName+" async2 :"+i);
                Thread.sleep(900);
            }
        } catch (InterruptedException e) {
            System.out.println("异常2....");
        }
    }
}
